/*
 * Copyright [2011] [Ambud Sharma/ODep Monitor]

   Licensed under the Apache License, Version 2.0 (the "License");

   you may not use this file except in compliance with the License.

   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software

   distributed under the License is distributed on an "AS IS" BASIS,

   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

   See the License for the specific language governing permissions and

   limitations under the License.
 */
package edu.uwsp.orion.odepm.main.server;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import edu.uwsp.orion.odepm.main.client.LoadFS;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class LoadFSImpl extends RemoteServiceServlet implements LoadFS {

	@Override
	public ArrayList<String> getDirectories() {
		 Configuration conf=new Configuration();
	     conf.set("fs.default.name", "hdfs://localhost:9000");
	     
	     ArrayList<String> temp=new ArrayList<String>();        
	     FileSystem fs = null;
		try {
			fs = FileSystem.get(conf);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	     Path path=fs.getHomeDirectory();
	     temp.add(path.getName());
	     FileStatus[] stats;
		try {
			stats = fs.listStatus(path);
			for(FileStatus sta:stats){
			       temp.add(sta.getPath().getName());
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	     
		return temp;
	}
}
